<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("../public/common.php");
include("../config/connect.php");

$id = CheckUrlParamNoDie("id");	
$opt = CheckUrlParamNoDie("opt");
$ref = CheckUrlParamNoDie("ref");
if ($ref=="")	$ref = "./";

if ($id == "")
{
	echo "error";
	exit;
}

//echo $ref.'**********';
$row = mysql_fetch_assoc(mysql_query("select id, tb_id, phone,email,password,nick_name,type from user where id=$id limit 1"));
$tbid = $row["tb_id"];
$phone = $row["phone"];
$email = $row["email"];
$pwd = $row["password"];
$userid = $row["id"];
$tb_id = $row["tb_id"];
$user_type = $row["type"];
//如果该支付宝账号有密码，就跳转到该ID的个人中心
if($pwd != ""){
	$url = "Location:".$ref;
	header($url);
	exit;
}
if(isset($_POST["submit"]))
{
	$lx_name=trim(GetPostParamStr("lx_name"));
	$lx_phone=trim(GetPostParamStr("lx_phone"));
	$lx_email=trim(GetPostParamStr("lx_email"));
	$sr_paw=md5(trim(GetPostParamStr("sr_paw")));
	$qr_paw=md5(trim(GetPostParamStr("qr_paw")));
	
	if($lx_name != "" && $sr_paw!="" && $qr_paw!="" && $sr_paw == $qr_paw && $pwd=="")
	{
		if($phone!=""){
			$sql="update user set nick_name='$lx_name', email='$lx_email', password='$sr_paw' where id=$id";
		}else if($email!=""){
			$sql="update user set nick_name='$lx_name', phone='$lx_phone', password='$sr_paw' where id=$id";
		}else if($phone == "" && $email == ""){
			$sql="update user set nick_name='$lx_name', phone='$lx_phone', email='$lx_email', password='$sr_paw' where id=$id";
		}
		mysql_query($sql);
		
		$_COOKIE["gwt_userid"] = $row["id"];
		$_COOKIE["gwt_zfb"] = $tbid;
		$_COOKIE["gwt_nickname"] = $row["nick_name"];
		$_COOKIE["gwt_phone"] = $row["phone"];
		$_COOKIE["gwt_email"] = $row["email"];
		
		//$url = "Location:./?id=".$row["id"]."&ref=".$ref;	// 跳到用户个人信息处
		$url = "Location:".$ref;
		header($url);
	}
	else
	{
		echo '<script>alert("您输入的信息不符！请联系购物兔客服：1753949757");window.history.go(-1);</script>';
	}
}

//$row = mysql_fetch_assoc(mysql_query("select id, tb_id, level, tubi, type from user where id='$id' limit 1"));
//$userid = $row["id"];
//$tb_id = $row["tb_id"];
//$user_type = $row["type"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>个人中心</title>
<style type="text/css">
body {font-size: 12px;color:#000;font-family: 宋体;}
.STYLE1 {font-size: 13px;font-weight: bold;}
table {border-collapse:collapse; border-spacing:2px;  font-size:12px;}
td,th { display:table-cell; vertical-align:inherit;}
img { border:0; vertical-align:top;}
a { text-decoration:none;}
a:hover { text-decoration:underline;}
#paw1,#paw2,#paw3,#paw4,#paw5 { width:200px; padding-left:10px; line-height:20px;}
#submint_btn { border-width:1px; border-color:#Fe0 #Fa0 #Fb0 #Fd0; border-style:solid; background:#Fc0; width:80px; height:30px; line-height:30px; font-size:14px; color:#fff; font-weight:bold;}
</style>
<script language="javascript" src="http://www.gouwutu.com/new/js/jquery.min.js"></script>
<script type="text/javascript" src="../js/addpsw.js"></script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="920" border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="#a8a8a8">
<tr>
    <td>
    <table width="920" height="102" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bar_bg.gif" >
      <tr>
        <td width="230" valign="top">&nbsp;</td>
        <td width="275" valign="top"><img src="images/bar_left_bg.gif" width="107" height="82" /></td>
        <td width="415" valign="top"><img src="images/user_n.gif" width="407" height="102" /></td>
      </tr>
    </table>
	<table width="920" align="center" cellpadding="0" cellspacing="0" border="0" style="background:#eee;">
  		<tr>
    		<td height="40" colspan="2"><span class="STYLE1">&nbsp;尊敬的  <?PHP echo $tb_id." "; if ($user_type == 'N') echo "用户"; else echo "联盟用户"; ?>，您好：&nbsp;</span></td>
  		</tr>
  		<tr height="95">
  			<td><div style=" background:url(images/wxts.gif) no-repeat center top; height:95px;"></div></td>
  		</tr>
  		<tr>
  			<td height="15" colspan="2" style="background:url(images/bg2011110701.jpg) no-repeat center top;"></td>
  		</tr>
  		<tr>
  			<td>
    	 	<form id="pawForm" action="add_psw.php?id=<?php echo $userid; ?>&ref=<?php echo $ref; ?>" method="post" onsubmit="return sPassword();">
            <table cellspacing="1" cellpadding="2" border="0" align="center">
            	<tr height="20"><td></td></tr>
                <tr height="45">
                    <td>个性昵称:</td>
                    <td></span><input type="text" name="lx_name" id="lx_name" onfocus="javascript:focusNicknameInput();" onblur="javascript:blurNicknameInput();" value="" style="width:200px;" /></td>
                    <td id="paw5"></td>
                </tr>
                    <?php
                    if($phone == "")
                    {
                        echo '<tr height="45"><td>联系方式:</td><td><input type="text" onfocus="javascript:focusPhoneInput();" onblur="javascript:blurPhoneInput();" name="lx_phone" id="lx_phone" value="" style="width:200px;" /></td><td id="paw1"></td></tr>';
                    }//else{
                      //  echo '<input type="hidden"  name="lx_email" id="lx_email" value="'.$phone.'">';
                    //}
                    ?>       
    
                    <?php
                    if($email == "")
					{
                        echo '<tr height="45"><td>电子邮件:</td><td><input type="text" onfocus="javascript:focusEmailInput();" onblur="javascript:blurEmailInput();" name="lx_email" id="lx_email" value="" style="width:200px;" /></td><td id="paw2"></td></tr>';
                    }
					//else{
                        //echo '<input type="hidden"  name="lx_email" id="lx_email" value="'.$email.'">';
                    //s}
                     ?>      
                <tr height="45">
                    <td>输入密码:</td>
                    <td><input type="password" onfocus="javascript:focusPasswordInput();" onblur="javascript:blurPasswordInput();" name="sr_paw" id="sr_paw" value="" style="width:200px;" /></td>
                    <td id="paw3"></td>
                </tr>
                <tr height="45">
                    <td>确认密码:</td>
                    <td><input type="password" onfocus="javascript:focusVPasswordInput();" onblur="javascript:blurVPasswordInput();" name="qr_paw" id="qr_paw" value="" style="width:200px;" /></td>
                    <td id="paw4"></td>
                </tr>
                <tr height="45" align="center">
                    <td colspan="3"><input type="submit" name="submit" id="submint_btn" value="确 定" />&nbsp;&nbsp;&nbsp;&nbsp;<a href="../myservices/index.php?id=<?php echo $id; ?>&opt=no" id="ZS" style="display:inline-block;">暂时还不想设置密码</a></td>
                    
                </tr>
                <tr height="30"><td></td></tr>
             </table>
         	</form>
    		</td>
  		</tr>
  
  		<tr>
  			<td height="45" colspan="2" style="background:url(images/bg2011102603.jpg) no-repeat center top;"></td>
  		</tr>
	</table>

    </td>
</tr>
</table>

<table cellpadding="0" cellspacing="0" border="0" width="920" align="center">
<tr>
	<td width="537" height="30" style="padding-left:5px; font-size:12px; color:#666">冰峰科技旗下购物兔 CopyRight 2011 gouwutu.com 粤ICP备11009208号</td>
    <td width="241"><span style="font-size:12px; color:#666">在线QQ客服：<a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1753949757&amp;site=qq&amp;menu=yes" target="_blank"><img align="absmiddle" title="欢迎点击和我们交流" src="http://wpa.qq.com/pa?p=2:1753949757:42" border="0" alt="点击和我们交流" /></a>&nbsp;&nbsp;&nbsp;</span></td>
    <td width="142" height="30" align="right" style="font-size:12px; color:#666"><a href="mailto:admin@gouwutu.com" target="_blank" style="font-size:12px; color:#666; font-weight:400; text-decoration:underline">联系我们</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</body>
</html>
